package com.blackitheima2.LambdaDemo.test4;

import java.util.Random;

//无参有返回值
public class TestRandom {
    public static void main(String[] args) {
        //匿名内部类
        getRandom(new HaveRandom() {
            @Override
            public int getNumber() {
                Random r=new Random();
                return r.nextInt(10)+1;
            }
        });
        //Lambda表达式
        getRandom(()->{
            Random r=new Random();
            return r.nextInt(10)+1;
        });
    }
    public static void getRandom(HaveRandom haveRandom){
       int result= haveRandom.getNumber();
    }
}
//接口
interface HaveRandom{
    public abstract int getNumber();
}
